package com.example.findfiledemo.service.impl;

import com.baidu.aip.speech.AipSpeech;
import com.example.findfiledemo.service.AnyQService;
import com.example.findfiledemo.service.VideoService;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VideoServiceImpl implements VideoService {
    //设置APPID/AK/SK
    public static final String APP_ID ="16993937";
    public static final String API_KEY = "hAjs979AguGn8stxYjD2QY0n";
    public static final String SECRET_KEY ="ybh87wtumuBFVPTAcqn2G6pOKb4Ccwyw";

    @Autowired
    private AnyQService anyQService;

    @Override
    public JSONObject getResult(byte[] file) {

        Logger logger = LoggerFactory.getLogger(VideoServiceImpl.class);
        // 初始化一个AipSpeech
        AipSpeech client = new AipSpeech(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置log4j日志输出格式，若不设置，则使用默认配置
        // 也可以直接通过jvm启动参数设置此环境变量
        System.setProperty("aip.log4j.conf", "log4j.properties");


        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 调用接口
        JSONObject res = client.asr(file, "wav", 16000, null);
        System.out.println(res.toString(2));

        return  res;

    }
}
